//
//  SuperviseReportCell.swift
//  SBSafetyApp
//
//  Created by Lina on 2023/1/5.
//

import Foundation
import UIKit

class SuperviseReportCell: UITableViewCell {
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        setupUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func reload(withModal modal: Any) {
        iconIV.image = UIImage(named: "ic_spreport_1")
        titleL.text = "上海银行营业、重控场所安全管理检查标准"
        netL.text = "延长支行"
        typeL.text = "日常检查"
        
        chargeL.text = "负责人：李四"
        participantL.text = "参与人：张启山"
        startDateL.text = "开始时间：2022-10-25"
        submitDateL.text = "提交时间：2022-10-25 14:25:01"
    }
    
    func setupUI() {
        addSubview(iconIV)
        iconIV.snp.makeConstraints { make in
            make.left.equalToSuperview().offset(10)
            make.top.equalToSuperview().offset(14)
            make.width.height.equalTo(25)
        }
        
        addSubview(titleL)
        titleL.snp.makeConstraints { make in
            make.left.equalTo(iconIV.snp.right).offset(15)
            make.right.equalToSuperview().offset(-30)
            make.top.equalToSuperview().offset(14)
        }
        
        addSubview(indicatorIV)
        indicatorIV.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-10)
            make.centerY.equalTo(titleL.snp.centerY)
            make.width.equalTo(10)
        }
        
        addSubview(netL)
        netL.snp.makeConstraints { make in
            make.top.equalTo(titleL.snp.bottom).offset(10)
            make.left.equalTo(titleL.snp.left)
            make.height.equalTo(20)
        }
        
        addSubview(typeL)
        typeL.snp.makeConstraints { make in
            make.top.equalTo(netL.snp.top)
            make.left.equalTo(netL.snp.right).offset(5)
            make.height.equalTo(20)
        }
        
        addSubview(contentBV)
        contentBV.snp.makeConstraints { make in
            make.top.equalTo(netL.snp.bottom).offset(12)
            make.left.equalTo(titleL.snp.left)
            make.right.equalToSuperview().offset(-20)
            make.bottom.equalToSuperview().offset(-12)
        }
        
        contentBV.addSubview(chargeL)
        chargeL.snp.makeConstraints { make in
            make.top.equalToSuperview().offset(18)
            make.left.equalToSuperview().offset(18)
            make.width.equalTo(115)
        }
        
        contentBV.addSubview(participantL)
        participantL.snp.makeConstraints { make in
            make.top.equalTo(chargeL.snp.bottom).offset(18)
            make.left.equalTo(chargeL.snp.left)
            make.width.equalTo(chargeL.snp.width)
            make.bottom.equalToSuperview().offset(-15)
        }
        
        contentBV.addSubview(startDateL)
        startDateL.snp.makeConstraints { make in
            make.top.equalTo(chargeL.snp.top)
            make.left.equalTo(chargeL.snp.right)
            make.right.equalToSuperview()
        }
        
        contentBV.addSubview(submitDateL)
        submitDateL.snp.makeConstraints { make in
            make.top.equalTo(participantL.snp.top)
            make.left.equalTo(startDateL.snp.left)
            make.right.equalToSuperview()
        }
        
        addSubview(arrIV)
        arrIV.snp.makeConstraints { make in
            make.bottom.equalTo(contentBV.snp.top)
            make.left.equalTo(contentBV.snp.left).offset(20)
        }
        
        let line = UIView()
        line.backgroundColor = .hex("#EFEFEF")
        addSubview(line)
        line.snp.makeConstraints { (make) -> Void in
            make.bottom.equalToSuperview()
            make.left.equalToSuperview().offset(10)
            make.right.equalToSuperview().offset(-10)
            make.height.equalTo(0.5)
        }
    }
    
    override func setHighlighted(_ highlighted: Bool, animated: Bool) {
        super.setHighlighted(highlighted, animated: animated)
        if highlighted {
            backgroundColor = .bg
        } else {
            backgroundColor = .white
        }
    }
    
    lazy var iconIV: UIImageView = {
        let imageView = UIImageView()
        imageView.contentMode = UIView.ContentMode.scaleAspectFit
        return imageView
    }()
    
    lazy var titleL: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 16)
        label.textColor = .hex("#333333")
        return label
    }()
    
    lazy var netL: PaddingLabel = {
        let label = PaddingLabel()
        label.insets = UIEdgeInsets(top: 0, left: 7, bottom: 0, right: 7)
        label.font = UIFont.systemFont(ofSize: 13)
        label.textColor = .hex("#019126")
        label.layer.cornerRadius = 4
        label.layer.borderColor = UIColor.hex("#019126").cgColor
        label.layer.borderWidth = 0.5
        return label
    }()
    
    lazy var typeL: PaddingLabel = {
        let label = PaddingLabel()
        label.insets = UIEdgeInsets(top: 0, left: 7, bottom: 0, right: 7)
        label.font = UIFont.systemFont(ofSize: 13)
        label.textColor = .primary
        label.layer.cornerRadius = 4
        label.layer.borderColor = UIColor.primary.cgColor
        label.layer.borderWidth = 0.5
        return label
    }()
    
    lazy var contentBV: UIView = {
        let view = UIView.createBase()
        view.backgroundColor = .hex("#F7F7F7")
        return view
    }()
    
    lazy var chargeL: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 12)
        label.adjustsFontSizeToFitWidth = true
        label.textColor = .hex("#A4A4A4")
        return label
    }()
    
    lazy var participantL: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 12)
        label.adjustsFontSizeToFitWidth = true
        label.textColor = .hex("#A4A4A4")
        return label
    }()
    
    lazy var startDateL: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 12)
        label.adjustsFontSizeToFitWidth = true
        label.textColor = .hex("#A4A4A4")
        return label
    }()
    
    lazy var submitDateL: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 12)
        label.adjustsFontSizeToFitWidth = true
        label.textColor = .hex("#A4A4A4")
        return label
    }()
    
    lazy var indicatorIV: UIImageView = {
        let imageView = UIImageView(image: UIImage(systemName: "chevron.right"))
        imageView.tintColor = .hex("#A5A5A5")
        imageView.contentMode = .scaleAspectFit
        return imageView
    }()
    
    lazy var arrIV: UIImageView = {
        let imageView = UIImageView(image: UIImage(named: "ic_sparr"))
        return imageView
    }()
}
